<div id="formDiv"></div>
<script type="text/html" id="warehouseProductionLineFormContent">
  <form lay-filter="warehouseProductionLineForm" id="warehouseProductionLineForm" class="layui-form open-form">
    <div class="open-model">
      <div class="open-auto">
        <input name="id" type="hidden" />
        <div class="layui-form-item ">
          <label class="layui-form-label">选择车间</label>
          <input type="hidden" name="workshopName" />
          <div class="layui-input-block">
            <select id="workshopId" name="workshopId" lay-filter="workshopId"></select>
          </div>
        </div>
        <div class="layui-form-item ">
          <label class="layui-form-label">产线编码</label>
          <div class="layui-input-block">
            <input type="text" class="layui-input" name="productionLineCode" />
          </div>
        </div>
        <div class="layui-form-item ">
          <label class="layui-form-label">产线名称</label>
          <div class="layui-input-block">
            <input type="text" class="layui-input" name="productionLineName" />
          </div>
        </div>
        <div class="layui-form-item ">
          <label class="layui-form-label">状态</label>
          <div class="layui-input-block">
            <input name="status" type="checkbox" lay-skin="switch" value="1" lay-text="启用|停用" />
          </div>
        </div>
        <div class="layui-form-item ">
          <label class="layui-form-label">备注</label>
          <div class="layui-input-block">
            <textarea name="remark" class="layui-textarea"></textarea>
          </div>
        </div>
        <div class="layui-form-item text-right">
          <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">关闭</button>
          <button class="layui-btn" lay-filter="formSubmit" type="button" lay-submit>提交</button>
        </div>
      </div>
    </div>
  </form>
</script>

<script>
  layui.use(["layer", "form", "table", "admin", "laydate", "upload", "laytpl"], async function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var config = layui.config;
    var admin = layui.admin;
    var upload = layui.upload;
    let laydate = layui.laydate;
    let laytpl = layui.laytpl;
    const nowData = { ...parentData };
    let data = nowData?.data;

    let skuList = [];

    laytpl(warehouseProductionLineFormContent.innerHTML).render({ ...nowData }, function (html) {
      $("#formDiv").after(html);
    });
    await admin.initDataSelectPro("enterprise/device/admin/deviceWorkshop/list", {}, "workshopId", "生产车间", (d, obj) => {
      form.val("warehouseProductionLineForm", {
        workshopName: ""
      });
      if (d.value) {
        form.val("warehouseProductionLineForm", {
          workshopName: obj.name
        });
      }
    });

    console.log(nowData);

    if (nowData.eventName === "detail") {
      admin.setFormDisable("#warehouseProductionLineForm", true);
    }

    if (data && data.id) {
      form.val("warehouseProductionLineForm", data);
    } else {
    }
    form.render();

    form.on("submit(formSubmit)", function (d) {
      let formData = { ...d.field };
      if (nowData.eventName == "add" || nowData.eventName == "edit") {
        formData.status = formData.status == 1 ? 1 : 0;
        admin.req(
          "warehouse/warehouse/productionLine/addOrUpdate",
          JSON.stringify(formData),
          function (res) {
            layer.closeAll("loading");
            if (res.code == 200) {
              layer.msg(res.msg, { icon: 1 });
              table.reload("warehouseProductionLine");
              layer.closeAll("page");
            } else {
              layer.msg(res.msg, { icon: 2, time: 1000 });
            }
          },
          "POST",
          false,
          "application/json"
        );
      }
      //  else if (nowData.eventName == "edit") {
      //   admin.req(
      //     "enterprise/purchase/admin/purchasePlan/update",
      //     JSON.stringify(formData),
      //     function (res) {
      //       layer.closeAll("loading");
      //       if (res.code == 200) {
      //         layer.msg(res.msg, { icon: 1 });
      //         table.reload("purchasePlanTable");
      //         layer.closeAll("page");
      //       } else {
      //         layer.msg(res.msg, { icon: 2, time: 1000 });
      //       }
      //     },
      //     "PUT",
      //     false,
      //     "application/json"
      //   );
      // }
      return false;
    });
  });
</script>

<style>
  #warehouseProductionLineForm .layui-form-item .layui-inline {
    /* margin-bottom: 5px; */
    margin-right: 0px;
  }
</style>
